package com.eidetic.storage.db;

import android.database.sqlite.SQLiteDatabase;

public class DatabaseSchema
{
	private static final String NOTE_TABLE_CREATE =
		"CREATE TABLE note ("
			+ "_id integer primary key autoincrement, "
			+ "photoPath text not null, "
			+ "caption text not null, "
			+ "dateCreated date, "
			+ "dateDue date"
			+ ");";
	
	private static final String TAG_TABLE_CREATE = 
		"CREATE TABLE tag ("
			+ "_id integer primary key autoincrement, "
			+ "name text not null, "
			+ "description text not null"
			+ ";)";
			
	private static final String TAG_MAP_TABLE_CREATE = 
		"CREATE TABLE tag_map ("
			+ "_id integer primary key autoincrement, "
			+ "note_id integer, "
			+ "tag_id integer"
			+ ");";
	
	public static final String SHARED_SERVICE_TABLE_CREATE =
		"CREATE TABLE shared_service ("
			+ "_id integer primary key autoincrement, "
			+ "name text not null"
			+ ");";
	
	public static void onCreate(SQLiteDatabase database)
	{
		database.execSQL(NOTE_TABLE_CREATE);
		database.execSQL(TAG_TABLE_CREATE);
		database.execSQL(TAG_MAP_TABLE_CREATE);
		database.execSQL(SHARED_SERVICE_TABLE_CREATE);
	}
	
	public static void onUpgrade(SQLiteDatabase database)
	{
		// TODO Log this action
		database.execSQL("DROP TABLE IF EXISTS note");
		database.execSQL("DROP TABLE IF EXISTS tag");
		database.execSQL("DROP TABLE IF EXISTS tag_map");
		database.execSQL("DROP TABLE IF EXISTS shared_service");
		onCreate(database);
	}
}	

